package models.common.bean;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;

import models.common.bean.ReceivablesPushCreditBean.AuditResult;

import services.common.UserFundService;

import common.constants.ConfConst;
import common.constants.Constants;
import common.enums.AuditStatus;
import common.enums.AuditUpdate;
import common.enums.IsBlackCompany;
import common.utils.Factory;
import common.utils.ResultInfo;
import common.utils.Security;

/**
 * 企业信息显示bean 用于显示企业基本信息、资金相关信息、投资信息等
 * 
 * @description
 * 
 * @author zhiliang.lan
 * @createDate 2017年4月17日
 */
@Entity
public class ShowCompanyInfo {

	@Id
	@GeneratedValue
	public long id;

	/** userId */
	public long user_id;
	
	@Transient
	public String userSign;// 加密ID

	public String getUserSign() {
		return Security.addSign(this.user_id, Constants.BID_ID_SIGN,
				ConfConst.ENCRYPTION_KEY_DES);
	}

	/** 操作时间 */
	public Date time;

	public String name;

	/** 企业全称 */
	public String full_name;

	/** 企业简称 */
	public String short_name;

	/** 用户名 */
	/*
	 * public String short_name;
	 */

	/** 手机号码 */
	public String mobile;

	/** 邮箱 */
	public String email;

	/** 可用余额 */
	public double balance;

	/** 冻结资金 */
	public double freeze;

	/** 登录次数 */
	public int login_count;

	/** 信用积分 */
	public int credit_point;

	/** 是否黑名单 */
	public int is_black;

	public IsBlackCompany getIs_black() {
		return IsBlackCompany.getEnum(this.is_black);
	}

	/** 最后登录时间 */
	public Date last_login_time;

	/** 是否允许登录 */
	public boolean is_allow_login;

	/** 待还 */
	public double no_repayment;

	/** 待收 */
	public double no_receive;

	/** 累计融通 */
	public double borrow_total;

	/** 累计投资 */
	public double invest_total;

	/** 基本资料审核状态 **/
	public int basic_info_audit_status;

	/** 小额金额鉴定审核状态 **/
	public int authenticate_status;

	/** 企业认证状态 **/
	public int company_authenticate_status;

	/** 企业类型名称 */
	public String company_type_name;

	/** 行业类型名称 **/
	public String industry_type_name;
	
	/**邮箱修改审核状态*/
	public int update_email_status;
	
	
	/**经办人信息修改审核状态*/
	public int agent_status;
	

	/*** 自动投标标识 0开 1关 */
	public boolean bid_switch;

	public ShowCompanyInfo() {
	}

	public ShowCompanyInfo(Long id, Date time, String full_name, String name,
			String short_name, String mobile, int basic_info_audit_status,
			int authenticate_status, int company_authenticate_status,
			String email, double balance, double freeze, int login_count,
			Date last_login_time, boolean is_allow_login, double no_repayment,
			double no_receive, double borrow_total, double invest_total,
			int credit_point, int is_black, String company_type_name,
			String industry_type_name, boolean bid_switch) {
		super();
		this.id = id;
		this.time = time;
		this.full_name = full_name;
		this.name = name;
		this.short_name = short_name;
		this.mobile = mobile;
		this.email = email;
		this.balance = balance;
		this.freeze = freeze;
		this.login_count = login_count;
		this.last_login_time = last_login_time;
		this.is_allow_login = is_allow_login;
		this.no_repayment = no_repayment;
		this.no_receive = no_receive;
		this.borrow_total = borrow_total;
		this.invest_total = invest_total;
		this.basic_info_audit_status = basic_info_audit_status;
		this.authenticate_status = authenticate_status;
		this.company_authenticate_status = company_authenticate_status;
		this.credit_point = credit_point;
		this.is_black = is_black;
		this.company_type_name = company_type_name;
		this.industry_type_name = industry_type_name;
		this.bid_switch = bid_switch;
	}

	@Transient
	public String sign;// 加密ID

	public String getSign() {
		return Security.addSign(this.id, Constants.BID_ID_SIGN,
				ConfConst.ENCRYPTION_KEY_DES);
	}

	/**
	 * 用户资金防篡改字段状态。true-正常；false-异常
	 */
	@Transient
	public boolean fund_sign_status;

	public boolean getFund_sign_status() {
		ResultInfo result = Factory.getService(UserFundService.class)
				.userFundSignCheck(this.id);
		if (result.code < 1) {
			return false;
		}

		return true;
	}

	/** '审核状态' */
	public AuditStatus getBasic_info_audit_status() {
		AuditStatus auditResult = AuditStatus
				.getEnum(this.basic_info_audit_status);
		return auditResult;
	}

	public void setBasic_info_audit_status(AuditStatus auditResult) {
		this.basic_info_audit_status = auditResult.code;
	}
	
	
	/** '修改邮箱审核状态' */
	public String getUpdate_email_status() {
		AuditUpdate auditResult = AuditUpdate
				.getEnum(this.update_email_status);
		return auditResult.value;
	}
	
	public void setUpdate_email_status(AuditUpdate auditResult) {
		this.update_email_status = auditResult.code;
	}
	/** '修改经办人信息申请审核状态' */
	public AuditUpdate getAgent_status() {
		AuditUpdate auditResult = AuditUpdate
				.getEnum(this.agent_status);
		return auditResult;
	}
	
	public void setAgent_status(AuditUpdate auditResult) {
		this.update_email_status = auditResult.code;
	}

}
